<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>供应商对账报表</title>
    <link rel="stylesheet" type="text/css"
          href="../css/jquery/jquery-ui-1.8.23.custom.css" media="screen">
    <link rel="stylesheet" type="text/css"
          href="../css/form/jquery.mrd.form.css" media="screen">
    <link rel="stylesheet" type="text/css"
          href="../css/jqgrid/ui.jqgrid.css" media="screen">
    <link rel="stylesheet" href="../css/weui.loading.css">
    <script type="text/javascript" src="../js/jquery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="../js/tableExport.js"></script>
    <script type="text/javascript" src="yxt-report"></script>
    <script type="text/javascript" src="balance"></script>
    <style>
        table {
            table-layout: fixed;
        }

        td {
            word-break: break-all;
            word-wrap: break-word;
        }
    </style>
</head>

<body>
<div id="declarationsDataTable">
    <fieldset id="mf_container0"
              class="replace-ui-jqgrid ui-widget ui-widget-content ui-corner-all mf_con">
        <div
                class="replace-ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix table_header">
            <a href="javascript:void(0)"
               class="replace-ui-jqgrid-titlebar-close HeaderButton tab_button"><span
                    class="ui-icon ui-icon-circle-triangle-s"></span> </a><span
                class="replace-ui-jqgrid-title">平台报表查询</span>
        </div>
        <!-- 			<form style="margin-right: 30px;"> -->
        <table id="mf_table0" class="mrdTable" style="width: 100%;">
            <tbody>
            <tr>
                <td id="td_label_10" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>业务编号：</label></td>
                <td id="td_control_10" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"><input
                        id="skey业务编号" name="businessId" value="" type="text"
                        style="width: 98%;"/></td>
                <td id="td_label_11" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>实际委托人：</label></td>
                <td id="td_control_11" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"><input
                        id="skey实际委托人" name="CREATOR" value="" type="text"
                        style="width: 98%;"></td>
                <td id="td_label_12" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label></label></td>
                <td id="td_control_12" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"></td>
            </tr>
            <tr>
                <td id="td_label_10" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>集装箱号：</label></td>
                <td id="td_control_10" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"><input
                        id="skey集装箱号" name="businessId" value="" type="text"
                        style="width: 98%;"/></td>
                <td id="td_label_11" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>报关费用：</label></td>
                <td id="td_control_11" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"><input
                        id="skey报关费用" name="CREATOR" value="" type="text"
                        style="width: 98%;"></td>
                <td id="td_label_12" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label></label></td>
                <td id="td_control_12" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"></td>
            </tr>
            <tr>
                <td id="td_label_10" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>申报口岸：</label></td>
                <td id="td_control_10" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"><input
                        id="skey申报口岸" name="businessId" value="" type="text"
                        style="width: 98%;"/></td>
                <td id="td_label_11" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>报关单号：</label></td>
                <td id="td_control_11" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"><input
                        id="skey报关单号" name="CREATOR" value="" type="text"
                        style="width: 98%;"></td>
                <td id="td_label_12" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label></label></td>
                <td id="td_control_12" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;"></td>
            </tr>
            <!-- 						<tr>
                                        <td id="td_label_10" align="right" valign="middle"
                                            style="width: 100px; height: 30px;"><label>线上充值金额：</label></td>
                                        <td id="td_control_10" class="" align="left" valign="middle"
                                            style="width: 250px; height: 30px;"><input
                                            id="skey线上充值MIN" name="businessId" value="" type="text"
                                            style="width: 98%;"  /></td>
                                        <td id="td_label_11" align="right" valign="middle"
                                            style="width: 100px; height: 30px;"><label> - &nbsp;&nbsp;&nbsp; </label></td>
                                        <td id="td_control_11" class="" align="left" valign="middle"
                                            style="width: 250px; height: 30px;"><input
                                            id="skey线上充值MAX" name="CREATOR" value="" type="text"
                                            style="width: 98%;"></td>
                                        <td id="td_label_12" align="right" valign="middle"
                                            style="width: 100px; height: 30px;"><label></label></td>
                                        <td id="td_control_12" class="" align="left" valign="middle"
                                            style="width: 250px; height: 30px;"></td>
                                    </tr>
                                    <tr>
                                        <td id="td_label_10" align="right" valign="middle"
                                            style="width: 100px; height: 30px;"><label>线下充值金额：</label></td>
                                        <td id="td_control_10" class="" align="left" valign="middle"
                                            style="width: 250px; height: 30px;"><input
                                            id="skey线下充值MIN" name="businessId" value="" type="text"
                                            style="width: 98%;"  /></td>
                                        <td id="td_label_11" align="right" valign="middle"
                                            style="width: 100px; height: 30px;"><label> - &nbsp;&nbsp;&nbsp; </label></td>
                                        <td id="td_control_11" class="" align="left" valign="middle"
                                            style="width: 250px; height: 30px;"><input
                                            id="skey线下充值MAX" name="CREATOR" value="" type="text"
                                            style="width: 98%;"></td>
                                        <td id="td_label_12" align="right" valign="middle"
                                            style="width: 100px; height: 30px;"><label></label></td>
                                        <td id="td_control_12" class="" align="left" valign="middle"
                                            style="width: 250px; height: 30px;"></td>
                                    </tr> -->
            <tr>
                <td id="td_label_14" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>业务提交时间：</label></td>
                <td id="td_control_14" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;">
                    <script>
                        var tmin = '2016-03-01'
                        var tdefault = new Date().toJSON().substr(0, 8) + "01"
                        document.write(
                                '<input id="skey起始时间" name="CONFIRM_TIME" value="' + tdefault
                                + '" min="' + tmin
                                + '" type="date" class="hasDatepicker" style="width: 98%;" />')
                    </script>
                    00:00:00
                </td>
                <td id="td_label_15" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>到：</label></td>
                <td id="td_control_15" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;">
                    <script>
                        var tmax = new Date().toJSON().substr(0, 10)
                        document.write(
                                '<input id="skey结束时间" name="CONFIRM_TIME" value="' + tmax
                                + '" max="' + tmax
                                + '" type="date" class="hasDatepicker" style="width: 98%;" />')
                    </script>
                    23:59:59
                </td>
                <td id="td_label_13" align="right" valign="middle"
                    style="width: 100px; height: 30px;"><label>快速查询：</label></td>
                <td id="td_control_13" class="" align="left" valign="middle"
                    style="width: 250px; height: 30px;">
                    <script src="../js/monthSelect.js"></script>
                </td>
            </tr>
            <tr class="mrdBtnTr">
                <td id="mf_buttons_container" colspan="6" align="right">
                    <input
                            type="button" id="queryButton"
                            class="ui-button ui-widget ui-state-default ui-corner-all"
                            role="button" aria-disabled="false" value="查询"
                            style="margin: 3px; font-size: 12px;">
                    <input
                            type="button" id="reset"
                            class="ui-button ui-widget ui-state-default ui-corner-all"
                            role="button" aria-disabled="false" value="重置"
                            style="margin: 3px; font-size: 12px;"><input
                        type="button" id="exportExcel"
                        class="ui-button ui-widget ui-state-default ui-corner-all"
                        role="button" aria-disabled="false" value="导出明细数据"
                        style="margin: 3px; font-size: 12px;">
                    <input
                            type="button" id="exportExcelReport"
                            class="ui-button ui-widget ui-state-default ui-corner-all"
                            role="button" aria-disabled="false" value="导出自动汇总数据"
                            style="margin: 3px; font-size: 12px;">

                    <input
                            type="button" id="show20DetailOnly"
                            class="ui-button ui-widget ui-state-default ui-corner-all"
                            role="button" aria-disabled="false" value="显示明细数据[前20条]"
                            style="margin: 3px; font-size: 12px;">

                    <input
                            type="button" id="showAll"
                            class="ui-button ui-widget ui-state-default ui-corner-all"
                            role="button" aria-disabled="false" value="显示所有明细数据"
                            style="margin: 3px; font-size: 12px;">

                    <input
                            type="button" id="showReportOnly"
                            class="ui-button ui-widget ui-state-default ui-corner-all"
                            role="button" aria-disabled="false" value="显示自动汇总结果"
                            style="margin: 3px; font-size: 12px;"></td>
            </tr>
            </tbody>
        </table>
        <!-- 			</form> -->
    </fieldset>
    <div class="ui-jqgrid ui-widget ui-widget-content ui-corner-all"
         id="gbox_declarationsDataGrid" dir="ltr" style="">
        <div class="ui-widget-overlay jqgrid-overlay"
             id="lui_declarationsDataGrid"></div>
        <div class="loading ui-state-default ui-state-active"
             id="load_declarationsDataGrid" style="display: none;">读取中...
        </div>
        <div class="ui-jqgrid-view" id="gview_declarationsDataGrid"
             style="font-size: 12px;">
            <div
                    class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix">
                <a role="link" href="javascript:void(0)"
                   class="ui-jqgrid-titlebar-close HeaderButton" style="right: 0px;"><span
                        class="ui-icon ui-icon-circle-triangle-n"></span></a><span
                    class="ui-jqgrid-title">自动汇总结果</span>
            </div>
            <div class="ui-state-default ui-jqgrid-hdiv" style="">
                <div class="ui-jqgrid-hbox">
                    <table id='table1' class="ui-jqgrid-htable table-report" style="width: 100%;"
                           role="grid"
                           aria-labelledby="gbox_declarationsDataGrid" cellspacing="0"
                           cellpadding="0" border="0">

                    </table>
                </div>
            </div>
            <div class="ui-jqgrid-bdiv" style="height: 100%; ">
                <div style="position: relative;">
                    <div></div>
                    <table id="declarationsDataGrid" tabindex="1" cellspacing="0"
                           cellpadding="0" border="0" role="grid"
                           aria-multiselectable="false"
                           aria-labelledby="gbox_declarationsDataGrid"
                           class="ui-jqgrid-btable" style="">

                    </table>
                </div>
            </div>
        </div>
        <div class="ui-jqgrid-resize-mark" id="rs_mdeclarationsDataGrid">&nbsp;</div>

    </div>
</div>

<div class="ui-jqgrid ui-widget ui-widget-content ui-corner-all"
     id="gbox_declarationsDataGrid" dir="ltr" style="">
    <div class="ui-widget-overlay jqgrid-overlay"
         id="lui_declarationsDataGrid"></div>
    <div class="loading ui-state-default ui-state-active"
         id="load_declarationsDataGrid" style="display: none;">读取中...
    </div>
    <div class="ui-jqgrid-view" id="gview_declarationsDataGrid"
         style="font-size: 12px;">
        <div
                class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix">
            <a role="link" href="javascript:void(0)"
               class="ui-jqgrid-titlebar-close HeaderButton" style="right: 0px;"><span
                    class="ui-icon ui-icon-circle-triangle-n"></span></a><span
                class="ui-jqgrid-title">明细结果</span>
        </div>
        <div class="ui-state-default ui-jqgrid-hdiv" style="">
            <div class="ui-jqgrid-hbox">
                <table id='table2' class="ui-jqgrid-htable table-main" style="width: 100%;"
                       role="grid"
                       aria-labelledby="gbox_declarationsDataGrid" cellspacing="0"
                       cellpadding="0" border="0">

                </table>
            </div>
        </div>
        <div class="ui-jqgrid-bdiv" style="height: 100%; ">
            <div style="position: relative;">
                <div></div>
                <table id="declarationsDataGrid" tabindex="1" cellspacing="0"
                       cellpadding="0" border="0" role="grid"
                       aria-multiselectable="false"
                       aria-labelledby="gbox_declarationsDataGrid"
                       class="ui-jqgrid-btable" style="">

                </table>
            </div>
        </div>
    </div>
    <div class="ui-jqgrid-resize-mark" id="rs_mdeclarationsDataGrid">&nbsp;</div>

</div>
</div>

<input id="companyId" type="hidden" value="">
<div id="loadingToast" class="weui_loading_toast">
    <div class="weui_mask_transparent"></div>
    <div class="weui_toast">
        <div class="weui_loading">
            <!-- :) -->
            <div class="weui_loading_leaf weui_loading_leaf_0"></div>
            <div class="weui_loading_leaf weui_loading_leaf_1"></div>
            <div class="weui_loading_leaf weui_loading_leaf_2"></div>
            <div class="weui_loading_leaf weui_loading_leaf_3"></div>
            <div class="weui_loading_leaf weui_loading_leaf_4"></div>
            <div class="weui_loading_leaf weui_loading_leaf_5"></div>
            <div class="weui_loading_leaf weui_loading_leaf_6"></div>
            <div class="weui_loading_leaf weui_loading_leaf_7"></div>
            <div class="weui_loading_leaf weui_loading_leaf_8"></div>
            <div class="weui_loading_leaf weui_loading_leaf_9"></div>
            <div class="weui_loading_leaf weui_loading_leaf_10"></div>
            <div class="weui_loading_leaf weui_loading_leaf_11"></div>
        </div>
        <p class="weui_toast_content">数据加载中</p>
    </div>
</div>
<!-- 	<a id="download_img" href="javascript:void(0)"></a> -->

<script>

    var jsonResult = {
        数据头: ['序号', '业务提交时间', '业务编号',
              '实际委托人', '收发货单位', '业务类型（进/出）',
              '业务供应商', '申报口岸', '集装箱号', '报关单号', '票数', '报关费用'],
        数据集: {}
    }
    var jsonReportResult = {
        数据头: ['实际委托人',
              '业务供应商', '票数', '报关费用'],
        数据集: {}
    }
    var 实时余额FIX = {}
    var 实时余额BUG = {}
    function showBalanceBug() {
        try {
            var a = "核对时间:" + 实时余额BUG.核对时间
            var asum = 0
            var bsum = 0
            for (var attr in 实时余额BUG) {
                var datas = 实时余额BUG[attr]
                if (typeof datas == "object") {
                    a += ("\n" + attr + ":" + JSON.stringify(datas))
                    asum += datas.实际余额
                    bsum += datas.账上余额
                    if (datas.实际余额 > datas.账上余额) {
                        a += "[多扣]"
                    }
                    if (datas.实际余额 < datas.账上余额) a += "[多给]"
                }
            }
            a += ("\n结余：" + (asum - bsum))
            alert(a)
        } catch (e) {
        }
    }
    try {
        for (var attr in 实时余额.数据集) {
            var datas = 实时余额.数据集[attr]
            实时余额FIX[datas[0]] = datas[1]
        }
        实时余额BUG['核对时间'] = new Date(实时余额.查询时间).toLocaleString()
    } catch (e) {
    }

    var 业务数据集FIX = {}
    var cusPosi = 2
    if (typeof(业务数据) == 'undefined') {
        confirm("请先登录", function () {
        }, function () {
        })
        location.replace("http://112.124.20.178:6060/login")
    }
    for (var attr in 业务数据.数据集) {
        var datas = 业务数据.数据集[attr]
        if (!业务数据集FIX[datas[cusPosi]]) {
            业务数据集FIX[datas[cusPosi]] = {}
        }
        业务数据集FIX[datas[cusPosi]][attr] = datas
    }

    var 充值数据集FIX = {}
    var 充值数据集FIX_first = {}
    var ccusPosi = 1
    for (var attr in 充值数据.数据集) {
        var datas = 充值数据.数据集[attr]
        if (!充值数据集FIX[datas[ccusPosi]]) {
            充值数据集FIX[datas[ccusPosi]] = {}
        }
        if (!充值数据集FIX_first[datas[ccusPosi]]) {
            充值数据集FIX_first[datas[ccusPosi]] = attr
        }
        充值数据集FIX[datas[ccusPosi]][attr] = datas
        if (attr < 充值数据集FIX_first[datas[ccusPosi]]) {
            充值数据集FIX_first[datas[ccusPosi]] = attr
        }
    }

    for (var attr in 业务数据集FIX) {
        var datas = 业务数据集FIX[attr]
        for (var iattr in datas) {
            var idatas = datas[iattr]
            jsonResult.数据集[iattr] = [0].concat(idatas).concat([0, 0, 0, 0])
        }
        var ddatas = 充值数据集FIX[attr]
        for (var iattr in ddatas) {
            var idatas = ddatas[iattr]
            jsonResult.数据集[iattr] =
                    [0].concat([idatas[0], '', idatas[1], '', '', '', '', '', '', '', 0, idatas[2],
                                idatas[3], 0, 0])
        }
    }

    var 结余数据集Dynamic = {}
    var fixjsonResult数据集 = function () {
        var datas = jsonResult.数据集
        var dkeys = Object.keys(datas).sort()
        for (var i = 0; i < dkeys.length; i++) {
            var attr = dkeys[i]
            var cname = datas[attr][3]
            if (充值数据集FIX_first[cname]) {
                if (充值数据集FIX_first[cname] > attr) {
                    datas[attr][12] = datas[attr][11]
                    结余数据集Dynamic[cname] = 0
                }
                else {
                    if (!结余数据集Dynamic[cname])结余数据集Dynamic[cname] = 0
                    datas[attr][14] = 结余数据集Dynamic[cname]
                    datas[attr][15] =
                            结余数据集Dynamic[cname] + datas[attr][12] + datas[attr][13]
                            - datas[attr][11]
                    结余数据集Dynamic[cname] = datas[attr][15]
                }
            }
            else {
                datas[attr][12] = datas[attr][11]
            }
        }
    }
    fixjsonResult数据集()

    var FINAL数据集;
    var sdates = {sdate: new Date('2016-03-01').getTime() * 10, edate: new Date().getTime() * 10}
    window.onload = function () {
        var container = $(".table-main")
        var containerReport = $(".table-report")
        var skeys = {}

        function 数据过滤(dbrow) {
            var result = true
            for (var attr in skeys) {
                if (!skeys[attr]) continue;
                try {
                    if (dbrow[attr].indexOf(skeys[attr]) == -1) {
                        result = false;
                        break;
                    }
                } catch (e) {
                    if (dbrow[attr] != (skeys[attr])) {
                        result = false;
                        break;
                    }
                }
            }
            return result
        }

        $("#skey申报口岸").on("keyup", function () {
            skeys[7] = this.value == "" ? undefined : this.value
            initTd()
        })
        $("#skey报关单号").on("keyup", function () {
            skeys[9] = this.value == "" ? undefined : this.value
            initTd()
        })
        $("#skey业务编号").on("keyup", function () {
            skeys[2] = this.value == "" ? undefined : this.value
            initTd()
        })
        $("#skey业务编号").on("keyup", function () {
            skeys[2] = this.value == "" ? undefined : this.value
            initTd()
        })
        $("#skey实际委托人").on("keyup", function () {
            skeys[3] = this.value == "" ? undefined : this.value
            initTd()
        })
        $("#skey业务供应商").on("keyup", function () {
            skeys[6] = this.value == "" ? undefined : this.value
            initTd()
        })
        $("#skey集装箱号").on("keyup", function () {
            skeys[8] = this.value == "" ? undefined : this.value
            initTd()
        })
        $("#skey报关费用").on("keyup", function () {
            skeys[11] = this.value == "" ? undefined : this.value
            initTd()
        })
        $("#skey起始时间").on("change", function () {
            var temp = new Date(this.value).getTime() * 10
            if (NaN != temp) {
                sdates.sdate = temp
                initTd()
            }
        })
        $("#skey结束时间").on("change", function () {
            //var temp = (new Date(this.value).getTime()+24*3600*1000-1)*10
            var temp = (new Date(this.value).getTime()) * 10
            if (NaN != temp) {
                sdates.edate = temp
                initTd()
            }
        })

        var initSdate = function () {
            var stemp = (new Date($("#skey起始时间").val() + ' 00:00:00').getTime()) * 10
            if (NaN != stemp) {
                sdates.sdate = stemp
            }
            //var etemp = (new Date($("#skey结束时间").val()+' 23:59:59').getTime()+24*3600*1000-1)*10
            var etemp = (new Date($("#skey结束时间").val() + ' 23:59:59').getTime()) * 10
            if (NaN != etemp) {
                sdates.edate = etemp
            }
            initTd()
        }
        $("#td_control_13 > a").on("click", function () {
            $("#skey起始时间").val($(this).attr("sdate"))
            $("#skey结束时间").val($(this).attr("edate"))
            initSdate()
        })
        initSdate()

        $("#queryButton").on("click", function () {
            initTd()
        })
        $("#reset").on("click", function () {
            skeys = {}
            $("input:text").val("")
            initTd()
        })
        var exportExcel = function (type) {
            var a = (skeys[3] ? firstRow[3] : "")
            var c = a.substring(0, a.indexOf("(") == -1 ? a.legnth : a.indexOf("(")).substring(0,
                                                                                               a.indexOf(
                                                                                                       "（")
                                                                                               == -1
                                                                                                       ? a.legnth
                                                                                                       : a.indexOf(
                                                                                                       "（"))
            a = (skeys[6] ? firstRow[6] : "")
            var s = a.substring(0, a.indexOf("(") == -1 ? a.legnth : a.indexOf("(")).substring(0,
                                                                                               a.indexOf(
                                                                                                       "（")
                                                                                               == -1
                                                                                                       ? a.legnth
                                                                                                       : a.indexOf(
                                                                                                       "（"))
            var filename = "一线通平台" +
                           new Date(sdates.sdate / 10).toJSON().substr(0, 10) + "-" +
                           new Date(sdates.edate / 10).toJSON().substr(0, 10) +
                           c + s

            if (type) {
                tableExport('table1', filename + '汇总表', 'xls');
            }
            else {
                tableExport('table2', filename + '明细表', 'xls');
            }
        }
        $("#exportExcel").on("click", function () {
            exportExcel()
        })
        $("#exportExcelReport").on("click", function () {
            exportExcel(1)
        })
        $("#showAll").on("click", function () {

            $("#loadingToast").show()
            $("#show20DetailOnly").click()
            var a = function () {
                initTd(true)
            }
            setTimeout(a, 1000)
        })
        $("#show20DetailOnly").on("click", function () {
            container.parent().parent().parent().show()
            containerReport.parent().parent().parent().hide()
        })
        $("#showReportOnly").on("click", function () {
            container.parent().parent().parent().hide()
            containerReport.parent().parent().parent().show()
        })
        $("#showSupTh").on("click", function () {
            $("#loadingToast").show()
            var a = function () {
                $(".table-main tr").each(function () {
                    $(this).find("th:eq(12)").hide()
                    $(this).find("th:eq(13)").hide()
                    $(this).find("th:eq(14)").hide()
                    $(this).find("th:eq(15)").hide()
                    $(this).find("td:eq(12)").hide()
                    $(this).find("td:eq(13)").hide()
                    $(this).find("td:eq(14)").hide()
                    $(this).find("td:eq(15)").hide()
                    $("#loadingToast").hide()
                })
                $(".table-report tr").each(function () {
                    $(this).find("th:eq(4)").hide()
                    $(this).find("th:eq(5)").hide()
                    $(this).find("th:eq(6)").hide()
                    $(this).find("th:eq(7)").hide()
                    $(this).find("th:eq(8)").hide()
                    $(this).find("td:eq(4)").hide()
                    $(this).find("td:eq(5)").hide()
                    $(this).find("td:eq(6)").hide()
                    $(this).find("td:eq(7)").hide()
                    $(this).find("td:eq(8)").hide()
                })
            }
            setTimeout(a, 1000)
        })
        $("#showAllTh").on("click", function () {
            $("#loadingToast").show()
            var a = function () {
                $(".table-main tr").each(function () {
                    $(this).find("th:eq(12)").show()
                    $(this).find("th:eq(13)").show()
                    $(this).find("th:eq(14)").show()
                    $(this).find("th:eq(15)").show()
                    $(this).find("td:eq(12)").show()
                    $(this).find("td:eq(13)").show()
                    $(this).find("td:eq(14)").show()
                    $(this).find("td:eq(15)").show()
                    $("#loadingToast").hide()
                })
                $(".table-report tr").each(function () {
                    $(this).find("th:eq(4)").show()
                    $(this).find("th:eq(5)").show()
                    $(this).find("td:eq(4)").show()
                    $(this).find("td:eq(5)").show()
                })
            }
            setTimeout(a, 1000)
        })
        function initReportTh() {
            var data = jsonReportResult.数据头
            var tr = $('"<tr></tr>"')
            for (var i = 0; i < data.length; i++) {
                tr.append($('<th id="declarationsDataGrid_declaration_port"' +
                            '										role="columnheader"' +
                            '										class="ui-state-default ui-th-column ui-th-ltr"'
                            +
                            '										style=""><span' +
                            '										class="ui-jqgrid-resize ui-jqgrid-resize-ltr"'
                            +
                            '										style="cursor: col-resize;">&nbsp;</span>'
                            +
                            '									<div id="jqgh_declarationsDataGrid_declaration_port"'
                            +
                            '											class="ui-jqgrid-sortable">'
                            +
                            '											' + data[i]
                            + '<span class="s-ico" style="display: none"><span' +
                            '												sort="asc"' +
                            '												class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span'
                            +
                            '												sort="desc"' +
                            '												class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span>'
                            +
                            '										</div></th>'))
            }
            containerReport.append(tr);
        }

        function initTh() {
            var data = jsonResult.数据头
            var tr = $('"<tr></tr>"')
            for (var i = 0; i < data.length; i++) {
                tr.append($('<th id="declarationsDataGrid_declaration_port"' +
                            '										role="columnheader"' +
                            '										class="ui-state-default ui-th-column ui-th-ltr"'
                            +
                            '										style=""><span' +
                            '										class="ui-jqgrid-resize ui-jqgrid-resize-ltr"'
                            +
                            '										style="cursor: col-resize;">&nbsp;</span>'
                            +
                            '									<div id="jqgh_declarationsDataGrid_declaration_port"'
                            +
                            '											class="ui-jqgrid-sortable">'
                            +
                            '											' + data[i]
                            + '<span class="s-ico" style="display: none"><span' +
                            '												sort="asc"' +
                            '												class="ui-grid-ico-sort ui-icon-asc ui-state-disabled ui-icon ui-icon-triangle-1-n ui-sort-ltr"></span><span'
                            +
                            '												sort="desc"' +
                            '												class="ui-grid-ico-sort ui-icon-desc ui-state-disabled ui-icon ui-icon-triangle-1-s ui-sort-ltr"></span></span>'
                            +
                            '										</div></th>'))
            }
            container.append(tr);
        }

        function 计算结余(截止时间) {
            var datas = jsonResult.数据集
            var cccusPosi = 3
            var result = {}
            for (var attr in datas) {
                if (attr / 10 >= 截止时间) continue;
                var data = datas[attr]
                if (result[data[cccusPosi]]) {
                    result[data[cccusPosi]]['报关费用'] += (data[11] - 0)
                    result[data[cccusPosi]]['票数'] += (data[10] - 0)
                    result[data[cccusPosi]]['线上充值'] += (data[12] - 0)
                    result[data[cccusPosi]]['线下充值'] += (data[13] - 0)
                } else {
                    result[data[cccusPosi]] = {
                        报关费用: data[11] - 0,
                        票数: data[10] - 0,
                        线上充值: data[12] - 0,
                        线下充值: data[13] - 0
                    }
                }
            }
            var sortkeys = Object.keys(datas).sort()
            var record = {}
            var recordstate = {}
            for (var ki = 0; ki < sortkeys.length; ki++) {
                var attr = sortkeys[ki]
                var data = datas[attr]
                if (result[data[cccusPosi]]) continue;
                if (data[12] + data[13] > 0) {
                    recordstate[data[cccusPosi]] = true
                }
                if (!recordstate[data[cccusPosi]]) {
                    if (record[data[cccusPosi]]) {
                        record[data[cccusPosi]] += (data[11] - 0)
                    } else {
                        record[data[cccusPosi]] = (data[11] - 0)
                    }
                }

            }
            for (var attr in record) {
                result[attr] = {报关费用: 0, 票数: 0, 线上充值: record[attr], 线下充值: 0}
            }
            return result
        }

        function 计算结余B(截止时间) {
            var datas = jsonResult.数据集
            var cccusPosi = 3
            var result = {}
            for (var attr in datas) {
                if (attr / 10 > 截止时间) continue;
                var data = datas[attr]
                if (result[data[cccusPosi]]) {
                    result[data[cccusPosi]]['报关费用'] += (data[11] - 0)
                    result[data[cccusPosi]]['票数'] += (data[10] - 0)
                    result[data[cccusPosi]]['线上充值'] += (data[12] - 0)
                    result[data[cccusPosi]]['线下充值'] += (data[13] - 0)
                } else {
                    result[data[cccusPosi]] = {
                        报关费用: data[11] - 0,
                        票数: data[10] - 0,
                        线上充值: data[12] - 0,
                        线下充值: data[13] - 0
                    }
                }
            }
            return result
        }

        function 计算FINAL数据集() {
            var datas = jsonResult.数据集
            var result = {}
            var seq = 1
            //for(var attr in datas) {
            var sortkeys = Object.keys(datas).sort()
            for (var ki = 0; ki < sortkeys.length; ki++) {
                var attr = sortkeys[ki]
                if (!数据过滤(datas[attr])) continue;
                if (attr < sdates.sdate) continue;
                if (attr > sdates.edate) continue;
                //fix firefox toJSON bug
                //result[attr] = [seq,new Date(datas[attr][1].replace(/-/gi, '/')).toJSON().substr(0,10)].concat(datas[attr].slice(2))

                result[attr] = [seq, datas[attr][1].substr(0, 10)].concat(datas[attr].slice(2))
                seq++
            }
            return result
        }

        var firstRow;

        function initTd(showAll) {
            //var sumA = 计算结余(sdates.sdate/10)
            //var sumB = 计算结余B(sdates.edate/10)

            FINAL数据集 = 计算FINAL数据集()

//get report
            var FINAL数据集Report = {};
            var FINAL数据集ReportFIX = {};
            var FINAL数据集ReportFIXTotal = [0, 0, 0, 0, 0, 0, 0];

            for (var attr in FINAL数据集) {
                var data = FINAL数据集[attr]
                if ("" == data[6]) continue;
                if (FINAL数据集Report[data[3]]) {
                    if (FINAL数据集Report[data[3]][data[6]]) {
                        FINAL数据集Report[data[3]][data[6]] =
                                [FINAL数据集Report[data[3]][data[6]][0] + data[10],
                                 FINAL数据集Report[data[3]][data[6]][1] + data[11]]
                    }
                    else {
                        FINAL数据集Report[data[3]][data[6]] = [data[10], data[11]]
                    }
                }
                else {
                    FINAL数据集Report[data[3]] = {}
                    FINAL数据集Report[data[3]][data[6]] = [data[10], data[11]]
                }
            }

            var dynamicSumByTimeData = {}
            var dynamicSumByTimeDataTotal = [0, 0]
            var dynamicSumByTime = function () {
                //for(var attr in FINAL数据集) {
                var iskeys = Object.keys(FINAL数据集).sort()
                for (var i = 0; i < iskeys.length; i++) {
                    var data = FINAL数据集[iskeys[i]]
                    var cname = data[3]
                    if (dynamicSumByTimeData[cname]) {

                    }
                    else {
                        dynamicSumByTimeData[cname] = {}
                        dynamicSumByTimeData[cname]['startSum'] = data[14]
                    }
                }
                var rkeys = Object.keys(FINAL数据集).reverse()
                for (var i = 0; i < rkeys.length; i++) {
                    var data = FINAL数据集[rkeys[i]]
                    var cname = data[3]
                    if (dynamicSumByTimeData[cname]['endSum'] != undefined) {

                    }
                    else {
                        dynamicSumByTimeData[cname]['endSum'] = data[15]
                    }
                }
                for (var attr in dynamicSumByTimeData) {
                    var data = dynamicSumByTimeData[attr]
                    dynamicSumByTimeDataTotal[0] += data['startSum']
                    dynamicSumByTimeDataTotal[1] += data['endSum']
                    if (undefined != 实时余额FIX[attr]) {
                        if (实时余额FIX[attr] != data['endSum'])
                            实时余额BUG[attr] = {账上余额: 实时余额FIX[attr], 实际余额: data['endSum']}
                    }
                }
            }
            dynamicSumByTime()
            FINAL数据集ReportFIXTotal[2] = dynamicSumByTimeDataTotal[0]
            FINAL数据集ReportFIXTotal[3] = dynamicSumByTimeDataTotal[1]

            var dynamicSumCZByTimeData = {}
            var dynamicSumCZByTimeDataTotal = [0, 0, 0]
            var dynamicSumCZByTime = function () {
                for (var attr in FINAL数据集) {
                    var data = FINAL数据集[attr]
                    var cname = data[3]
                    if (dynamicSumCZByTimeData[cname]) {
                        dynamicSumCZByTimeData[cname][0] += data[12]
                        dynamicSumCZByTimeData[cname][1] += data[13]
                    }
                    else {
                        dynamicSumCZByTimeData[cname] = [data[12], data[13]]
                    }
                }
                for (var attr in dynamicSumCZByTimeData) {
                    var data = dynamicSumCZByTimeData[attr]
                    data[2] = (data[0] + data[1])
                    dynamicSumCZByTimeDataTotal[0] += data[0]
                    dynamicSumCZByTimeDataTotal[1] += data[1]
                    dynamicSumCZByTimeDataTotal[2] += data[2]
                }
            }
            dynamicSumCZByTime()
            FINAL数据集ReportFIXTotal[4] = dynamicSumCZByTimeDataTotal[0]
            FINAL数据集ReportFIXTotal[5] = dynamicSumCZByTimeDataTotal[1]
            FINAL数据集ReportFIXTotal[6] = dynamicSumCZByTimeDataTotal[2]

            var tempId = 0
            for (var attr in FINAL数据集Report) {
                var data = FINAL数据集Report[attr]
                for (iattr in data) {
                    FINAL数据集ReportFIX[tempId] =
                            [attr, iattr, data[iattr][0], data[iattr][1],
                             dynamicSumByTimeData[attr]['startSum'],
                             dynamicSumByTimeData[attr]['endSum']
                                , dynamicSumCZByTimeData[attr][0], dynamicSumCZByTimeData[attr][1],
                             dynamicSumCZByTimeData[attr][2]]
                    FINAL数据集ReportFIXTotal[0] += data[iattr][0]
                    FINAL数据集ReportFIXTotal[1] += data[iattr][1]
                    tempId++
                }
            }
            FINAL数据集ReportFIX['总计'] = ['', '总计'].concat(FINAL数据集ReportFIXTotal)

            containerReport.empty()
            initReportTh()
            for (var attr in FINAL数据集ReportFIX) {
                var data = FINAL数据集ReportFIX[attr]
                var tr = $("<tr class=\"ui-widget-content jqgrow ui-row-ltr\"></tr>")
                for (var i = 0; i < data.length; i++) {

                    var temp = "";
                    if(typeof data[i] == 'number' && i!=2){
                        temp = data[i].toFixed(2);
                    }else{
                        temp = data[i];
                    }

                    tr.append($("<td>" + temp + "</td>"))

                }
                containerReport.append(tr);
            }
//get report end
            var dynamicSum = {}
            for (var attr in FINAL数据集) {
                /*var data = FINAL数据集[attr]
                 try {
                 var sumAA = sumA[data[3]]
                 if(sumAA) {
                 data[14] = sumAA['线上充值']+sumAA['线下充值']-sumAA['报关费用']
                 }
                 else {
                 data[14] = 0
                 }
                 var sumBB = sumB[data[3]]
                 if(sumBB) {
                 data[15] = sumBB['线上充值']+sumBB['线下充值']-sumBB['报关费用']
                 }
                 else {
                 data[15] = 0
                 }
                 //dynamicSum[data[3]] = [data[14], data[14]+data[12]+data[13]-data[10]]
                 }catch(e){}

                 /*try {
                 if(dynamicSum[data[3]]) {
                 var pbalance = dynamicSum[data[3]][1]
                 dynamicSum[data[3]] = [pbalance, pbalance+data[12]+data[13]-data[11]]
                 }
                 else {
                 var pbalance = sumA[data[3]]?sumA[data[3]]:0
                 dynamicSum[data[3]] = [pbalance, pbalance+data[12]+data[13]-data[11]]
                 }
                 data[14]=dynamicSum[data[3]][0]
                 data[15]=dynamicSum[data[3]][1]
                 }catch(e){}*/
            }
            var total = {报关费用: 0, 票数: 0, 线上充值: 0, 线下充值: 0, 起始时间结余: '-', 结束时间结余: '-'}
            for (var attr in FINAL数据集) {
                var data = FINAL数据集[attr]
                total['报关费用'] += (data[11] - 0)
                total['票数'] += (data[10] - 0)
                total['线上充值'] += (data[12] - 0)
                total['线下充值'] += (data[13] - 0)
            }
            /*for(var attr in sumB) {
             var sumBB = sumB[attr]
             if(attr.indexOf(skeys[3]?skeys[3]:'')==-1) continue;
             total['结束时间结余']+=(sumBB['线上充值']+sumBB['线下充值']-sumBB['报关费用'])
             }
             for(var attr in sumA) {
             var sumAA = sumA[attr]
             if(attr.indexOf(skeys[3]?skeys[3]:'')==-1) continue;
             total['起始时间结余']+=(sumAA['线上充值']+sumAA['线下充值']-sumAA['报关费用'])
             }*/
            FINAL数据集['总计'] = ['', '', '', '', '', '', '', '', '', '总计：',
                              total.票数, total.报关费用, total.线上充值, total.线下充值, total.起始时间结余,
                              total.结束时间结余]

            container.empty()
            initTh()
            var datas = FINAL数据集
            //http://www.admin5.com/article/20120718/445724.shtml
            var pagecount = 0
            //for(var attr in datas) {
            var 总计Show = false
            var sortkeys = Object.keys(datas).sort()
            for (var ki = 0; ki < sortkeys.length; ki++) {
                var attr = sortkeys[ki]
                if (pagecount > 20) {
                    if (!showAll)break;
                }
                pagecount++

                var data = datas[attr]
                if (ki == 0) firstRow = data

                if (!showAll) {
                    if ('总计' == attr) 总计Show = true
                    if (pagecount == 21 && !总计Show) data = datas['总计']
                }

                var tr = $("<tr class=\"ui-widget-content jqgrow ui-row-ltr\"></tr>")
                for (var i = 0; i < data.length; i++) {

                    var temp = "";
                    if(typeof data[i] == 'number' && i!=0 && i!=10){
                        temp = data[i].toFixed(2);
                    }else{
                        temp = data[i];
                    }

                    try {
                        if (i == jsonResult.编辑头) {
                            tr.append($("<td><a href='" + jsonResult.编辑URL + "?id=" + attr + "'>"
                                        + temp + "</a></td>"))
                        }
                        else {
                            tr.append($("<td>&nbsp;" + temp + "</td>"))
                        }
                    } catch (e) {
                        tr.append($("<td>&nbsp;" + temp + "</td>"))
                    }
                }
                container.append(tr);
            }
            $("#loadingToast").hide()
        }

        try {
            自定义数据集()
        } catch (e) {
        }
        initTh()
        initReportTh()
        initTd()
        $("#show20DetailOnly").click()
        try {
            自定义页面初始化()
        } catch (e) {
        }
    }

</script>
</body>
</html>
